package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.ElasticsearchService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class SendLogListener {
    @Autowired
    private ElasticsearchService elasticsearchService;
//      监听发送日志队列
    @RabbitListener(queues = RabbitMQConstants.TOPIC_SMS_SEND_LOG)
    public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException {
        //1. 保存submit对象到ES服务
        elasticsearchService.saveLog(submit);

        //2. 手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
